﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Collections.ObjectModel;

namespace StoryMaker.Application
{
    public class PageViewTemplateSelector : DataTemplateSelector
    {
        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            ContentPresenter element = container as ContentPresenter;
            if (element != null && item != null && item is Page)
            {
                DataTemplate dataTemplate = element.TryFindResource("PageDataTemplate") as DataTemplate;
                if (dataTemplate != null)
                {
                    return dataTemplate;
                }
            }
            else if (element != null && item != null && item is ObservableCollection<Page>)
            {
                DataTemplate dataTemplate = element.TryFindResource("PagesDataTemplate") as DataTemplate;
                if (dataTemplate != null)
                {
                    return dataTemplate;
                }
            }
            return base.SelectTemplate(item, container);
        }
    }
}
